#[test]
fn find_extension_test() {
    let filename = "foo.rs";

    let ext = match filename.find(".") {
        None => None,
        Some(i) => Some(&filename[i + 1..]),
    };
    assert_eq!("rs", ext.unwrap());

    let ext = filename.find(".").map(|i| &filename[i + 1..]);
    assert_eq!("rs", ext.unwrap());

    let ext = filename.find(".").and_then(|i| Some(&filename[i + 1..]));
    assert_eq!("rs", ext.unwrap());
}

fn str2num(num_str: &str) -> i32 {
    num_str.parse::<i32>().unwrap()
}

#[test]
fn str_to_num_test() {
    assert_eq!(1, str2num("1"))
}

use std::fs::File;
use std::io::{self, Read};

fn read_file_demo(fname: &str) -> Result<String, io::Error> {
    let mut f = File::open(fname)?;
    println!("f {:?}", f);
    let mut buf = String::new();
    let _ = f.read_to_string(&mut buf);

    Ok(buf)
}

#[test]
fn read_file_test() {
    let fname = "/etc/hosts";
    let body = match File::open(fname) {
        Ok(mut f) => {
            println!("f {:?}", f);
            let mut buf = String::new();
            let n = f.read_to_string(&mut buf);
            println!("read {:?}, body {}", n, buf);
            Ok(buf)
        }
        Err(e) => Err(e),
    };

    assert_eq!(read_file_demo(fname).unwrap(), body.unwrap());
}
